package app.services;

import app.enums.GenreCode;
import app.enums.PublicationTypeCode;
import app.models.Genre;
import app.models.PublicationType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Kseniya Artsiukhova <kartsiukhova@productiveedge.com>
 */
public class PublicationTypeServiceImpl implements PublicationTypeService {

    @Override
    public Map<PublicationTypeCode, List<GenreCode>> publicationTypeListWithGenres() {
        Map<PublicationTypeCode, List<GenreCode>> map = new HashMap<PublicationTypeCode, List<GenreCode>>();

        for (PublicationTypeCode code : PublicationTypeCode.values()) {
            List<Genre> genres = getGenreListByPublicationTypeCode(code);
            List<GenreCode> genreCodes = new ArrayList<GenreCode>();

            for (Genre g : genres) {
                GenreCode genreCode = GenreCode.getGenreCodeByGenreName(g.getGenreName());
                if (genreCode != null) {
                    genreCodes.add(genreCode);
                }
            }
            map.put(code, genreCodes);
        }
        return map;
    }

    @Override
    public List<Genre> getGenreListByPublicationTypeCode(PublicationTypeCode code) {
        PublicationType publicationType = PublicationType.getPublicationTypeByCode(code.getTypeName());
        return publicationType.getGenres();
    }
}
